<?php
//模板函数
function status($status){
    if($status==1){
        $str="<span class='label  label-success   radius'>正常</span>";
    }elseif($status==0){
        $str="<span  class='label  label-danger  radius'>待审</span>";
    }else{
        $str="<span  class='label  label-danger  radius'>删除</span>";
    }
    return $str;
}
function showstatus($status){
    if($status==1){
       $str="<span  class='label  label-success   radius'>启用</span>";
    }elseif($status==0){
       $str="<span  class='label  label-danger  radius'>禁用</span>";
    }else{
        $str="<span  class='label  label-danger  radius'>删除</span>";
    }
    
    return $str;
}


//是否默认(城市)
function Isdefault($is_default){
    if($is_default==1){
       $str="<span class='label  label-success   radius'>默认</span>";
    }elseif($is_default==0){
       $str="<span  class='label  label-danger  radius'>非默认</span>";
    }
    
    return $str;
}
//是否总店
function Ismain($is_main){
    if($is_main==1){
       $str="<span class='label  label-success   radius'>总店</span>";
    }elseif($is_main==0){
       $str="<span  class='label  label-danger  radius'>不是</span>";
    }
    
    return $str;
}





/**
 * doCurl 
 * $type: 0 get 1 post 
 * $data 数组数据
 * 
 * ***/
function  doCurl($url,$type=0,$data=[]){
    $ch=curl_init();//初始化 
      //设置
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch,CURLOPT_HEADER,0);
      if($type==1){
          //post
          curl_setopt($ch,CURLOPT_POST,1);
          curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
      }
      //执行并获取内容
       $output=curl_exec($ch);
       //释放句柄 结束curl
       curl_close($ch);
       return $output;   
}

// 商户入驻申请的文案
function bisRegister($status) {
    if($status == 1) {
        $str = "入驻申请成功";
    }elseif($status == 0) {
        $str = "待审核，审核后平台方会发送邮件通知，请关注邮件";

    }elseif($status == 2) {
        $str = "非常抱歉，您提交的材料不符合条件，请重新提交";
    }else {
        $str = "该申请已被删除";
    }
    return $str;
}

/**
 ** 通用函数pagination();
 *****/
function pagination($obj){
    if(!$obj){
        return "";
    }
    //分页优化
    $params=request()->param();
    return '<div class="cl pd-5 bg-1 bk-gray mt-20  tp5-o2o">'.$obj->appends($params)->render().'</div>';
    
}

/**通用函数***/
function getSeCityName($path){
    if(empty($path)){
        return "";
    }
   if(preg_match("/,/",$path)){
        $cityPath=explode(",",$path);
        $cityId=$cityPath[1];
    }else{
        $cityId=$path;
    }
    
    $city=model("City")->get($cityId);
    return $city->name;
}
//
function getSeCategoryName($path){
    if(empty($path)){
        return "";
    }
    if(preg_match("/,/",$path)){
        $categoryPath=explode(",",$path);
        $categoryId=$categoryPath[1];
    }
    $category=model("Category")->get($categoryId);
    return $category->name;
}

//计算店面总数
function countLocation($ids) {
    if(!$ids) {
        $arr1="1";
        return count($arr1);
    }

    if(preg_match('/,/', $ids)) {
        $arr = explode(',', $ids);
        return count($arr);
    }
}

//tradeSn 
function setOrderSn(){
    list($t1,$t2)=explode(" ", microtime());
    //echo $t1."</br>";
    //echo $t2."</br>"; exit();
    $t3=explode(".",$t1*10000);
   return $t2.$t3[0].(rand(10000,99999));
}
//支付状态
function showpay($status,$message,$data=[]){
    $result=[
        "status"=>intval($status),
        "message"=>$message,
        "data"=>$data,
    ];
    return $result;
}

function showmiss($status,$message,$data=[]){
    $result=[
        'status'=>intval($status),
        'message'=>$message,
        'data'=>$data,
    ];
    exit(json_encode($result));
}
